<template>
	<!-- 资产录入/编辑 -->
	<div class="assetArchiveEditPage">
		<CommonTitle titleName="承租方信息">
			<template #rightCnBox>
				<div class="titleRight">
					<el-button plain class="button_cancel2" @click="cancelEdit"
						>取消{{ pageType === "edit" ? "编辑" : "录入" }}</el-button
					>
					<el-button
						plain
						class="button_view"
						:disabled="saveDisFlag"
						@click="doSave"
						>保存</el-button
					>
				</div>
			</template>
		</CommonTitle>
		<div class="inpuBox">
			<el-form
				:inline="true"
				:model="baseForm"
				ref="baseFormRef"
				:rules="baseState.rules"
				class="demo-form-inline"
				label-position="right"
				label-width="100px"
			>
				<el-row>
					<el-col :span="23">
						<el-form-item
							style="width: 100%"
							label="资产名称"
							prop="assetsName"
						>
							<el-input
								v-model="baseForm.assetsName"
								maxlength="32"
								placeholder="请输入"
							></el-input>
						</el-form-item>
					</el-col>
				</el-row>
				<el-row>
					<el-col :span="7">
						<el-form-item
							class="regionSelectBox"
							label="资产位置"
							prop="regionCode"
						>
							<el-select
								v-model="baseForm.regionCode"
								placeholder="请选择区域"
								@change="areaTypeChange"
							>
								<el-option
									v-for="item in regionOptionsArr"
									:key="item.code"
									:label="item.name"
									:value="item.code"
								>
								</el-option>
							</el-select>
						</el-form-item>
						<el-form-item class="streetSelectBox" label="" prop="streetCode">
							<el-select
								v-model="baseForm.streetCode"
								style="flex: 3"
								placeholder="请选择街道"
							>
								<el-option
									v-for="item in streetOptionsArr"
									:key="item.code"
									:label="item.name"
									:value="item.code"
								>
								</el-option>
							</el-select>
						</el-form-item>
					</el-col>
					<el-col :span="15" :offset="1">
						<el-form-item style="width: 100%" label="详细地址" prop="address">
							<el-input
								v-model="baseForm.address"
								placeholder="点击选择地理位置"
								readonly
								@click="showMapDialog"
							>
							</el-input>
						</el-form-item>
					</el-col>
				</el-row>

				<el-row>
					<el-col :span="7">
						<el-form-item style="width: 100%" label="资产状态" prop="status">
							<el-select
								v-model="baseForm.status"
								style="width: 100%"
								placeholder="选择资产状态"
							>
								<el-option
									v-for="item in assetsStateOptionsArr"
									:key="item.value"
									:label="item.label"
									:value="item.value"
								>
								</el-option>
							</el-select>
						</el-form-item>
					</el-col>
					<el-col :span="7" :offset="1">
						<el-form-item
							style="width: 100%"
							label="资产权属"
							prop="assetsOwner"
						>
							<el-input
								v-model="baseForm.assetsOwner"
								maxlength="32"
								placeholder="请输入"
							></el-input>
						</el-form-item>
					</el-col>
					<el-col :span="7" :offset="1">
						<el-form-item style="width: 100%" label="资产类型" prop="type">
							<el-select
								v-model="baseForm.type"
								style="width: 100%"
								placeholder="选择资产类型"
							>
								<el-option
									v-for="item in assetsTypeOptionsArr"
									:key="item.value"
									:label="item.label"
									:value="item.value"
								>
								</el-option>
							</el-select>
						</el-form-item>
					</el-col>
				</el-row>

				<el-row>
					<el-col :span="7">
						<el-form-item
							style="width: 100%"
							label="取得方式"
							prop="sourceType"
						>
							<el-select
								v-model="baseForm.sourceType"
								style="width: 100%"
								placeholder="选择取得方式"
							>
								<el-option
									v-for="item in assetsGetTypeOptionsArr"
									:key="item.value"
									:label="item.label"
									:value="item.value"
								>
								</el-option>
							</el-select>
						</el-form-item>
					</el-col>
					<el-col :span="7" :offset="1">
						<el-form-item
							style="width: 100%"
							label="取得日期"
							prop="sourceTime"
						>
							<el-date-picker
								v-model="baseForm.sourceTime"
								value-format="YYYY-MM-DD"
								type="date"
								placeholder="选择取得日期"
								:disabled-date="disabledDate"
								:shortcuts="bookBuildingForm.shortcutsArr"
								size="large"
							>
							</el-date-picker>
						</el-form-item>
					</el-col>
					<el-col :span="7" :offset="1">
						<el-form-item
							style="width: 100%"
							label="处置日期"
							prop="manageTime"
						>
							<el-date-picker
								v-model="baseForm.manageTime"
								value-format="YYYY-MM-DD"
								type="date"
								placeholder="选择处置日期"
								:disabled-date="disabledDate"
								:shortcuts="bookBuildingForm.shortcutsArr"
								size="large"
							>
							</el-date-picker>
						</el-form-item>
					</el-col>
				</el-row>
				<el-row>
					<el-col :span="7">
						<el-form-item
							style="width: 100%"
							label="资产价值"
							prop="assetsWorth"
						>
							<el-input
								v-model="baseForm.assetsWorth"
								placeholder="请输入资产价值(单位：元)"
								@input="
									baseForm.assetsWorth = limitInputNum(
										baseForm.assetsWorth,
										9,
										2,
										true
									)
								"
							>
							</el-input>
						</el-form-item>
					</el-col>
					<el-col :span="7" :offset="1">
						<el-form-item
							style="width: 100%"
							label="责任部门"
							prop="departmentName"
						>
							<el-input
								disabled
								v-model="getUserDepartment"
								placeholder="请输入责任部门"
							>
							</el-input>
						</el-form-item>
					</el-col>
					<el-col :span="7" :offset="1">
						<el-form-item
							style="width: 100%"
							label="物业单位"
							prop="propertyCompanyName"
						>
							<el-input
								v-model="baseForm.propertyCompanyName"
								placeholder="请选择物业单位"
								readonly
								@click="focusPropertyCompany"
							>
							</el-input>
						</el-form-item>
					</el-col>
				</el-row>

				<el-row>
					<el-col :span="7">
						<el-form-item style="width: 100%" label="建筑面积" prop="buildArea">
							<el-input
								v-model="baseForm.buildArea"
								placeholder="请输入资产建筑面积(单位：㎡)"
								@input="
									baseForm.buildArea = limitInputNum(
										baseForm.buildArea,
										9,
										2,
										true
									)
								"
							>
							</el-input>
						</el-form-item>
					</el-col>
					<el-col :span="7" :offset="1">
						<el-form-item
							style="width: 100%"
							label="停车场面积"
							prop="parkingArea"
						>
							<el-input
								v-model="baseForm.parkingArea"
								placeholder="请输入资产停车场面积(单位：㎡)"
								@input="
									baseForm.parkingArea = limitInputNum(
										baseForm.parkingArea,
										9,
										2,
										true
									)
								"
							>
							</el-input>
						</el-form-item>
					</el-col>
					<el-col :span="7" :offset="1">
						<el-form-item
							style="width: 100%"
							label="自用面积"
							prop="selfUseArea"
						>
							<el-input
								v-model="baseForm.selfUseArea"
								placeholder="请输入资产自用(办公)面积(单位：㎡)"
								@input="
									baseForm.parkingArea = limitInputNum(
										baseForm.parkingArea,
										9,
										2,
										true
									)
								"
							>
							</el-input>
						</el-form-item>
					</el-col>
				</el-row>

				<el-row>
					<el-col :span="7">
						<el-form-item
							style="width: 100%"
							label="移交面积"
							prop="handoverArea"
						>
							<el-input
								v-model="baseForm.handoverArea"
								placeholder="请输入资产移交面积(单位：㎡)"
								@input="
									baseForm.handoverArea = limitInputNum(
										baseForm.handoverArea,
										9,
										2,
										true
									)
								"
							>
							</el-input>
						</el-form-item>
					</el-col>
					<el-col :span="7" :offset="1" v-if="pageType === 'edit'">
						<el-form-item
							style="width: 100%"
							label="可租赁面积"
							prop="leaseAbleArea"
						>
							<el-input
								disabled
								v-model="baseForm.leaseAbleArea"
								placeholder="请输入资产可租赁面积"
								@input="
									baseForm.leaseAbleArea = limitInputNum(
										baseForm.leaseAbleArea,
										9,
										2,
										true
									)
								"
							>
							</el-input>
						</el-form-item>
					</el-col>
					<el-col :span="7" :offset="1" v-if="pageType === 'edit'">
						<el-form-item
							style="width: 100%"
							label="可用面积"
							prop="usableArea"
						>
							<el-input
								disabled
								v-model="baseForm.usableArea"
								placeholder="请输入资产可用面积"
								@input="
									baseForm.usableArea = limitInputNum(
										baseForm.usableArea,
										9,
										2,
										true
									)
								"
							>
							</el-input>
						</el-form-item>
					</el-col>
				</el-row>
			</el-form>
		</div>

		<CommonTitle v-if="pageType === 'edit'" titleName="租赁信息" />
		<div class="inpuBox" v-if="pageType === 'edit'">
			<el-form
				:inline="true"
				:model="baseForm"
				class="demo-form-inline"
				label-position="right"
				label-width="100px"
			>
				<el-row>
					<el-col :span="7">
						<el-form-item style="width: 100%" label="已租面积">
							<el-input
								disabled
								v-model="baseForm.leasedArea"
								placeholder="请输入"
							>
							</el-input>
						</el-form-item>
					</el-col>
					<el-col :span="7" :offset="1">
						<el-form-item style="width: 100%" label="闲置面积">
							<el-input
								disabled
								v-model="baseForm.leaseUnusedArea"
								placeholder="请输入"
							>
							</el-input>
						</el-form-item>
					</el-col>
					<el-col :span="7" :offset="1">
						<el-form-item style="width: 100%" label="出租率">
							<el-input
								disabled
								v-model="baseForm.leaseRate"
								placeholder="请输入"
							>
							</el-input>
						</el-form-item>
					</el-col>
				</el-row>
			</el-form>
		</div>

		<CommonTitle titleName="相关文件" />
		<div class="inpuBox docImgBox">
			<el-form
				:inline="true"
				:model="docForm"
				class="demo-form-inline"
				label-position="right"
				label-width="100px"
			>
				<el-row>
					<el-col :span="24">
						<el-form-item style="width: 100%" label="资产实景图">
							<el-upload
								name="img"
								list-type="picture-card"
								:http-request="uploadFile"
								:before-upload="beforePicUpload"
								:file-list="docForm.picFileList"
								:limit="5"
								:on-exceed="exceedFiles"
								:on-success="upProblemPicSuccess"
								:on-remove="removeProblemPic"
							>
								<el-icon><Plus /></el-icon>
								<template #tip>
									<div class="el-upload__tip" style="width: 175px">
										只能上传 JPG、PNG 格式， 100M 以内，最多上传 5 张
									</div>
								</template>
							</el-upload>
							<el-dialog
								v-model="docForm.picDialogVisibleFlag"
								title="图片预览"
								width="30%"
								:close-on-click-modal="false"
							>
								<img style="width: 100%" :src="docForm.dialogImageUrl" alt="" />
							</el-dialog>
						</el-form-item>
					</el-col>
				</el-row>
				<el-divider border-style="dashed" />
				<el-row>
					<el-col :span="24">
						<el-form-item class="noBgBox" style="width: 100%" label="其他文件">
							<el-upload
								class="upload-demo"
								name="document"
								:http-request="uploadFile"
								accept=".doc,.docx,.pdf,.PDF,.rar,.zip"
								:before-upload="beforeDocUpload"
								:file-list="docForm.docFileList"
								:on-remove="handleDocRemove"
								:on-success="upDocSuccess"
							>
								<el-button type="primary" class="button_edit">上传文件</el-button>
								<template #tip>
									<div class="el-upload__tip">上传文件需小于2G</div>
								</template>
							</el-upload>
						</el-form-item>
					</el-col>
				</el-row>
			</el-form>
		</div>

		<CommonTitle v-if="pageType === 'edit'" titleName="建档信息" />
		<div class="inpuBox" v-if="pageType === 'edit'">
			<el-form
				:inline="true"
				:model="baseForm"
				class="demo-form-inline"
				label-position="right"
				label-width="100px"
			>
				<el-row>
					<el-col :span="7">
						<el-form-item style="width: 100%" label="建档时间">
							<!-- <el-date-picker
                v-model="baseForm.createTime"
                value-format="YYYY-MM-DD"
                type="date"
                disabled
                placeholder="档案创建时间"
                :shortcuts="bookBuildingForm.shortcutsArr"
                size="large"
              /> -->
							<el-input
								v-model="baseForm.createTime"
								placeholder="档案创建时间"
								readonly
							>
							</el-input>
						</el-form-item>
					</el-col>
				</el-row>
			</el-form>
		</div>
		<SelectPropertyCompanyDialog
			ref="propertyCompanyDlgRef"
			@getPropertyInfo="getPropertyInfo"
		/>
		<SelectAddressDialog ref="mapDialogRef" @getMapAddrInfo="getAddrInfo" />
	</div>
</template>

<script setup>
import {ref, reactive, onMounted, watch} from "vue";
import CommonTitle from "@/components/CommonTitle.vue";
import SelectPropertyCompanyDialog from "./components/selectPropertyCompanyDialog.vue";
import SelectAddressDialog from "./components/selectAddressDialog.vue";
import {getURLhandler, limitInputNum} from "@/common/utils/GlobalUtils";
import { useRoute, useRouter } from "vue-router";
import {
	ElForm,
	ElFormItem,
	ElRow,
	ElCol,
	ElSelect,
	ElOption,
	ElImage,
	ElDivider,
	ElDatePicker,
	ElDialog,
	ElUpload,
	ElMessage,
	ElMessageBox,
	ElLoading,
} from "element-plus";
import { Plus } from "@element-plus/icons-vue";
import { useStore } from "vuex";
import dayjs from "dayjs";
import {
	assetsTypeOptionsArr,
	assetsGetTypeOptionsArr,
	assetsStateOptionsArr,
} from "@/common/dict/dictCollect";
import { assetsApi, fileControlApi } from "@/api/assets";
import {clearCache} from "@/utils/createRoutes";
const route = useRoute();
const router = useRouter();
const store = useStore();

const getAssetsId = getURLhandler(route.path).id;
const pageType = getURLhandler(route.path).pageType;

const getUserDepartment = store.state.user.departmentName;
const getAccessToken = store.state.user.accessToken;
const saveDisFlag = ref(false);
const actionUrl =
	process.env.NODE_ENV === "development"
		? "/baseApi/"
		: process.env.VUE_APP_URL;

const baseFormRef = ref(null);
const baseForm = reactive({
	assetsName: "",
	regionCode: "",
	streetCode: "",
	status: null,
	assetsOwner: "",
	type: "",
	sourceType: "",
	sourceTime: "",
	manageTime: "",
	buildArea: "",
	parkingArea: "",
	selfUseArea: "",
	handoverArea: "",
	leaseAbleArea: "",
	usableArea: "",
	longitude: "",
	latitude: "",
	address: "",
	propertyCompanyName: "",
	propertyCompanyId: "",
	assetsWorth: "",
	leasedArea: "",
	leaseUnusedArea: "",
	leaseRate: "",
	createTime: "",
});
const baseState = reactive({
	rules: {
		assetsName: [
			{ required: true, trigger: "blur", message: "请填写资产名称" },
		],
		status: [{ required: true, trigger: "change", message: "请选择资产状态" }],
		type: [{ required: true, trigger: "blur", message: "请选择资产类型" }],
		sourceType: [
			{ required: true, trigger: "blur", message: "请选择取得方式" },
		],
		sourceTime: [
			{ required: true, trigger: "blur", message: "请选择取得日期" },
		],
		buildArea: [
			{ required: true, trigger: "blur", message: "请输入资产建筑面积" },
		],
		address: [{ required: true, trigger: "change", message: "请选择详细地址" }],
		regionCode: [{ required: true, trigger: "change", message: "请选择区域" }],
		streetCode: [{ required: true, trigger: "change", message: "请选择街道" }],
	},
});

const regionOptionsArr = ref([]);
const streetOptionsArr = ref([]);
// 初始化获取区域
const initAreaOptions = (type, cd) => {
	// type：1-获取区域 ；2-获取街道
	// cd：获取区域时不传
	assetsApi.getLocations(type, cd).then((res) => {
		const { code, data, msg } = res;
		if (code == 200) {
			if (cd) {
				streetOptionsArr.value = data;
			} else {
				regionOptionsArr.value = data;
			}
		}
	});
};
// 选择区域后获取街道选项
const areaTypeChange = (val) => {
	initAreaOptions(2, val);
};

// 物业单位相关
const propertyCompanyDlgRef = ref(null);
const focusPropertyCompany = () => {
	propertyCompanyDlgRef.value.open();
};
const getPropertyInfo = (val) => {
	baseForm.propertyCompanyName = val.propertyCompanyName;
	baseForm.propertyCompanyId = val.propertyCompanyId;
};

// 地图弹窗
const mapDialogRef = ref(null);
const showMapDialog = () => {
	mapDialogRef.value.openMap();
};
const getAddrInfo = (val) => {
	baseForm.longitude = val.lng;
	baseForm.latitude = val.lat;
	baseForm.address = val.address;
};

// 上传相关
const docForm = reactive({
	fileUpHeader: { Authorization: `${getAccessToken}` },
	picFileList: [],
	docFileList: [],
	picDialogVisibleFlag: false,
	dialogImageUrl: "",
	postImgsArr: [],
	postDocsArr: [],
});
const beforePicUpload = (file, index) => {
	let isImg = false;
	if (!/^image\/(jpeg|png|jpg)$/.test(file.type)) {
		ElMessage({
			type: "error",
			message: "上传图片仅支持 JPG、PNG、格式!",
		});
	} else {
		isImg = true;
	}
	const isLt100M = file.size / 1024 / 1024 < 100;
	if (!isLt100M) {
		ElMessage({
			type: "error",
			message: "上传图片大小不能超过 100MB!",
		});
	}
	return isImg && isLt100M;
};
const beforeDocUpload = (file, index) => {
	// file.size (单位为b，1024b=1KB)
	if (file.size / 1024 / 1024 / 1024 > 2) {
		ElMessage({
			type: "warning",
			message: "上传文件大小不能超过2G",
		});
		return false;
	}
	return true;
};
const removeProblemPic = (file, fileList) => {
	console.log("要删的？？？？", file);
	// 从传参数据中删除
	docForm.postImgsArr.map((n, i) => {
		if (n.fileName == file.name) {
			docForm.postImgsArr.splice(i, 1);
		}
	});
};

// el-upload 选择文件后
const uploadFile = (file) => {
	let uploadFile = new FormData();
	uploadFile.append("file", file.file);
	uploadFile.append("associationId", getAssetsId);
	uploadFile.append("businessType ", 2);
	const loadingInstance = ElLoading.service({
		lock: true,
		text: "Loading",
		background: "rgba(0, 0, 0, 0.7)",
	});

	fileControlApi.uploadImgFile(uploadFile).then((response) => {
		const { code, data, msg } = response;
		if (code == 200) {
			loadingInstance.close();
			let obj = {
				fileId: data.fileId,
				fileType: file.filename === "img" ? 1 : 2, // 1图片 2文件
				businessType: 2, // 1房源业务，2资产业务
				associationId: data.associationId, // 关联编号id - 新增时不传
				fileName: data.fileName,
				fileUrlKey: data.fileUrlKey,
				fileAddress: data.fileAddress,
			};
			if (file.filename === "document") {
				docForm.postDocsArr.push(obj);
			}
			if (file.filename === "img") {
				docForm.postImgsArr.push(obj);
			}
		} else {
			loadingInstance.close();
			ElMessage({
				type: "error",
				message: msg,
			});
		}
	});
};

const upProblemPicSuccess = (response, file, fileList) => {
	const { code, data, msg } = response;
	if (code == 200) {
		let obj = {
			fileId: data.fileId,
			fileType: 1, // 1图片 2文件
			businessType: 2, // 1房源业务，2资产业务
			associationId: data.associationId, // 关联编号id - 新增时不传
			fileName: data.fileName,
			fileUrlKey: data.fileUrlKey,
			fileAddress: data.fileAddress,
		};
		docForm.postImgsArr.push(obj);
	} else {
		ElMessage({
			type: "error",
			message: msg,
		});
	}
};

const exceedFiles = (files, fileList) => {
	ElMessage({
		type: "error",
		message: "至多可以上传5张图片",
	});
};

const picturePreview = (file) => {
	if (file.raw.type.includes("image/")) {
		docForm.dialogImageUrl = file.response.data.fileAddress.split("?")[0];
		docForm.picDialogVisibleFlag = true;
	}
};
const upDocSuccess = (response, file, fileList) => {
	const { code, data, msg } = response;
	if (code == 200) {
		let obj = {
			fileId: data.fileId,
			fileType: 2, // 1图片 2文件
			businessType: 2, // 1房源业务，2资产业务
			associationId: data.associationId, // 新增时不传
			fileName: data.fileName,
			fileUrlKey: data.fileUrlKey,
			fileAddress: data.fileAddress,
		};
		docForm.postDocsArr.push(obj);
	} else {
		ElMessage({
			type: "error",
			message: msg,
		});
	}
};
const handleDocRemove = (file, fileList) => {
	console.log("要删的？？？？", file);
	// 从传参数据中删除
	docForm.postDocsArr.map((n, i) => {
		if (n.fileName == file.name) {
			docForm.postDocsArr.splice(i, 1);
		}
	});
	// 从接口删除 - 3.23日接口报错
	let associationId = file.response.data.associationId;
	let urlKey = file.response.data.fileUrlKey;
	fileControlApi.fileDelete(associationId, urlKey).then((res) => {
		const { code } = res;
		if (code == 200) {
			ElMessage({
				type: "success",
				message: "删除文件成功",
			});
		}
	});
};

const bookBuildingForm = reactive({
	shortcutsArr: [
		{
			text: "今天",
			value: new Date(),
		},
		{
			text: "昨天",
			value: () => {
				const date = new Date();
				date.setTime(date.getTime() - 3600 * 1000 * 24);
				return date;
			},
		},
		{
			text: "一周前",
			value: () => {
				const date = new Date();
				date.setTime(date.getTime() - 3600 * 1000 * 24 * 7);
				return date;
			},
		},
	],
});
const disabledDate = (time) => {
	return dayjs(time) > Date.now();
};

const doSave = () => {
	baseFormRef.value.validate((vaild) => {
		if (vaild) {
			saveDisFlag.value = true;
			baseForm.files = [...docForm.postImgsArr, ...docForm.postDocsArr];
			if (pageType === "edit") {
				baseForm.assetsId = getAssetsId;
				assetsApi.updateAssets(baseForm).then((res) => {
					const { code, data, msg } = res;
					if (code === '200') {
						ElMessage({
							type: "success",
							message: "资产信息已更新",
						});
						setTimeout(() => {
							router.push({ path: "/asset/company/assetInformation" });
							saveDisFlag.value = false;
						}, 1000);
						clearCache({title:'资产信息录入'});
					} else {
						saveDisFlag.value = false;
					}
				});
			}

			if (pageType === "add") {
				// 新增
				assetsApi.addAssets(baseForm).then((res) => {
					const { code, data, msg } = res;
					if (code === '200') {
						ElMessage({
							type: "success",
							message: msg,
						});
						setTimeout(() => {
							router.push({ path: "/asset/company/assetInformation" });
						}, 1000);
						saveDisFlag.value = false;
					} else {
						saveDisFlag.value = false;
					}
				});
			}
		}
	});
};
const iconUrl = require("@/assets/iconImg/warning.png");
const cancelEdit = () => {
	// 确认弹窗
	ElMessageBox.confirm(
		"<img style='width:20px;height:20px;margin-right: 5px;' src=" +
			iconUrl +
			" />是否确认不保存档案已设置的数据？",
		"提示",
		{
			customClass: "deletConfirmBox",
      confirmButtonText: "确认",
      confirmButtonClass: "button_view",
      cancelButtonText: "取消",
      cancelButtonClass: "button_cancel2",
			dangerouslyUseHTMLString: true,
			center: true,
			closeOnClickModal: false,
			showClose: false,
		}
	)
		.then(() => {
			clearCache({title:'资产信息录入'});
			router.push({ path: "/asset/company/assetInformation" });
		})
		.catch(() => {});
};

// 编辑时获取的文件数据转换后赋值
const getTextDataChange = (arr) => {
	// 图片
	let newPicArr = arr.filter((n) => {
		return n.fileType == 1;
	});
	if (newPicArr.length) {
		docForm.picFileList = newPicArr.map((n, i) => {
			let obj = {
				name: n.fileName,
				url: n.fileAddress,
			};
			return obj;
		});
		docForm.postImgsArr = newPicArr;
	}
	// 文件
	let newDocArr = arr.filter((n) => {
		return n.fileType == 2;
	});
	if (newDocArr.length) {
		docForm.docFileList = newDocArr.map((n, i) => {
			let obj = {
				name: n.fileName,
				url: n.fileAddress,
			};
			return obj;
		});
		docForm.postDocsArr = newDocArr;
	}
};

/**
 * 监听form,用户在输入
 */
watch(baseForm,(value)=>{
	store.commit("setAssetInfoForm", baseForm);
},{deep:true})

const initForm = () => {
	if (store.state.collaborativeApproval.assetInfoForm) {
		for (let key in store.state.collaborativeApproval.assetInfoForm) {
			for (let key2 in baseForm) {
				baseForm[key] = store.state.collaborativeApproval.assetInfoForm[key];
			}
		}
	}
};


onMounted(async () => {
	initAreaOptions(1);
	if (pageType === "edit") {
		// 编辑时查询
		await assetsApi.getAssetsDetail(getAssetsId).then((res) => {
			const { code, data, msg } = res;
			if (code == 200) {
				Object.keys(baseForm).forEach((key) => {
					baseForm[key] = data[key];
				});
				// 获取的文件数据转换
				getTextDataChange(data.files);
			}
		});
		areaTypeChange(baseForm.regionCode || 1);
	}

	if(pageType !== 'edit'){
		initForm();
	}
});
</script>

<style lang="scss" scoped>
.assetArchiveEditPage {
	.titleRight {
		flex: 1;
		display: flex;
		justify-content: flex-end;
	}
	.inpuBox {
		padding: 32px 76px 15px;
		border-radius: 10px;
		border: 1px solid #e3e7f1;
		margin-bottom: 38px;
	}
}
</style>

<style lang="scss" scoped>
.assetArchiveEditPage {
	.inpuBox {
		.demo-form-inline {
			.el-form-item {
				margin-bottom: 34px;
				.el-form-item__label {
					font-size: 16px;
					font-family: SourceHanSansMedium;
				}
				.el-form-item__content {
					.el-date-editor.el-input,
					.el-date-editor.el-input__wrapper {
						width: 100%;
						.el-input__wrapper {
							width: 100%;
						}
					}
				}
			}
			.regionSelectBox {
				width: 58%;
				margin-right: 7px;
			}
			.streetSelectBox {
				width: 40%;
				margin-right: 0;
			}
			.noBgBox {
				.el-form-item__content {
					background: none;
				}
			}
		}
	}
	.docImgBox {
		.el-upload-list__item-actions {
			.el-upload-list__item-preview {
				display: none;
			}
			.el-upload-list__item-delete {
				margin-left: 2px;
			}
		}
		.upload-demo {
			width: 100%;
			.el-upload-list {
				.el-upload-list__item {
					width: 220px;
					margin-right: 80px;
					float: left;
				}
			}
		}
	}
}
</style>
